﻿<?xml version="1.0" encoding="utf-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2007/rif#">
  <payload>
    <Group>
      <sentence>
        <Forall>
          <id>
            <Const type="xsd:string">purchaseRule</Const>
          </id>
          <declare>
            <Var>customer</Var>
          </declare>
          <declare>
            <Var>purchaseYTD</Var>
          </declare>
          <formula>
            <Implies>
              <if>
                <And>
                  <formula>
                    <Member>
                      <instance>
                        <Var>customer</Var>
                      </instance>
                      <class>
                        <Const type="rif:iri">http://example.com/2008/joe#customer.Customer</Const>
                      </class>
                    </Member>
                  </formula>
                  <formula>
                    <Frame>
                      <object>
                        <Var>customer</Var>
                      </object>
                      <slot ordered="yes">
                        <Const type="rif:iri">purchaseYTD</Const>
                        <Var>purchaseYTD</Var>
                      </slot>
                    </Frame>
                  </formula>
                  <formula>
                    <External>
                      <content>
                        <Atom>
                          <op>
                            <Const type="rif:iri">http://www.w3.org/2007/rif-builtin-predicate#numeric-greater-than</Const>
                          </op>
                          <args ordered="yes">
                            <Var>purchaseYTD</Var>
                            <Const type="xsd:decimal">5000</Const>
                          </args>
                        </Atom>
                      </content>
                    </External>
                  </formula>
                </And>
              </if>
              <then>
                <Do>
                  <actions ordered="yes">
                    <Modify>
                      <target>
                        <Frame>
                          <object>
                            <Var>customer</Var>
                          </object>
                          <slot ordered="yes">
                            <Const type="rif:iri">status</Const>
                            <Const type="xsd:string">Gold</Const>
                          </slot>
                        </Frame>
                      </target>
                    </Modify>
                  </actions>
                </Do>
              </then>
            </Implies>
          </formula>
        </Forall>
      </sentence>
      <sentence>
        <Forall>
          <id>
            <Const type="xsd:string">DisplayStatus</Const>
          </id>
          <declare>
            <Var>customer</Var>
          </declare>
          <declare>
            <Var>name</Var>
          </declare>
          <formula>
            <Implies>
              <if>
                <And>
                  <formula>
                    <Member>
                      <instance>
                        <Var>customer</Var>
                      </instance>
                      <class>
                        <Const type="rif:iri">http://example.com/2009/prd#customer.Customer</Const>
                      </class>
                    </Member>
                  </formula>
                  <formula>
                    <Exists>
                      <declare>
                        <Var>purchaseYTD</Var>
                      </declare>
                      <declare>
                        <Var>s</Var>
                      </declare>
                      <formula>
                        <And>
                          <formula>
                            <Frame>
                              <object>
                                <Var>customer</Var>
                              </object>
                              <slot ordered="yes">
                                <Const type="rif:iri">name</Const>
                                <Var>name</Var>
                              </slot>
                            </Frame>
                          </formula>
                          <formula>
                            <Frame>
                              <object>
                                <Var>customer</Var>
                              </object>
                              <slot ordered="yes">
                                <Const type="rif:iri">status</Const>
                                <Var>s</Var>
                              </slot>
                            </Frame>
                          </formula>
                          <formula>
                            <External>
                              <content>
                                <Atom>
                                  <op>
                                    <Const type="rif:iri">http://www.w3.org/2007/rif-builtin-predicate#numeric-equal</Const>
                                  </op>
                                  <args ordered="yes">
                                    <Var>s</Var>
                                    <Const type="xsd:string">Gold</Const>
                                  </args>
                                </Atom>
                              </content>
                            </External>
                          </formula>
                        </And>
                      </formula>
                    </Exists>
                  </formula>
                </And>
              </if>
              <then>
                <Do>
                  <actions ordered="yes">
                    <Execute>
                      <target>
                        <Atom>
                          <op>
                            <Const type="rif:iri">http://www.w3.org/2007/rif-builtin-action#print</Const>
                          </op>
                          <args ordered="yes">
                            <External>
                              <content>
                                <Expr>
                                  <op>
                                    <Const type="rif:iri"> http://www.w3.org/2007/rif-builtin-function#concat</Const>
                                  </op>
                                  <args ordered="yes">
                                    <Var>name</Var>
                                    <Const type="xsd:string"> has Gold status </Const>
                                  </args>
                                </Expr>
                              </content>
                            </External>
                          </args>
                        </Atom>
                      </target>
                    </Execute>
                  </actions>
                </Do>
              </then>
            </Implies>
          </formula>
        </Forall>
      </sentence>
    </Group>
  </payload>
</Document>